﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace GUI
{
    public class DataService : DataTable
    {
        static SqlConnection cn;
        SqlDataAdapter da;
        SqlCommand cm;
        string connStr = @"Data Source=.\SQLEXPRESS; Initial Catalog=QLCHH; Integrated Security=True";

        public void Load(SqlCommand command)
        {
            if (cn == null || cn.State == ConnectionState.Closed)
            {
                cn = new SqlConnection(connStr);
                cn.Open();
            }
            cm = command;
            cm.Connection = cn;

            da = new SqlDataAdapter(cm);
            this.Clear();
            da.Fill(this);
        }
    }
}
